﻿using NicoViewLib.Model.Comments;
using NicoViewLib.Model.Comments.BodyTexts;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NicoViewUnitTest
{
    [TestFixture]
    class NicoCommentBodyUnitTest
    {



        [TestCase]
        public void ParseTestCasePlane()
        {
            ParseTest("testBody", new INicoCommentBodyText[] { new NicoPlainBodyText("testBody") });
        }

        [TestCase]
        public void ParseTestCaseUrl()
        {
            ParseTest("http://test.ne.jp/sm25544664 あいうえお", new INicoCommentBodyText[] { new NicoUrlBodyText("http://test.ne.jp/sm25544664"), new NicoPlainBodyText(" あいうえお") });
        }

        [TestCase]
        public void ParseTestCaseUrlAndVideoId()
        {
            ParseTest("sm25544664 http://test.ne.jp あいうえお", new INicoCommentBodyText[] {new NicoVideoIdBodyText("sm25544664"),new NicoPlainBodyText(" "), new NicoUrlBodyText("http://test.ne.jp"), new NicoPlainBodyText(" あいうえお") });
        }

        [TestCase]
        public void ParseTestCaseNoAnchor()
        {
            ParseTest(">>44 http://test.ne.jp あいうえお", new INicoCommentBodyText[] { new NicoSingleNoAnchorBodyText(44),new NicoPlainBodyText(" "),new NicoUrlBodyText("http://test.ne.jp"),new NicoPlainBodyText(" あいうえお")});
        }

        [TestCase]
        public void ParseTestCaseRangeAnchor()
        {
            ParseTest(">>55-66あいうえお", new INicoCommentBodyText[] { new NicoRangeNoAnchorBodyText(55, 66), new NicoPlainBodyText("あいうえお") });
        }

        
        [TestCase]
        public void ParseTestCaseAnchorHtmlTag()
        {
            ParseTest(@"<a href=""http://test.ne.jp"">こちらをクリック</a>",new INicoCommentBodyText[]{ new NicoAnchorHtmlTagBodyText("こちらをクリック", "http://test.ne.jp", new INicoCommentBodyText[] {new NicoPlainBodyText(@"<a href="""),new NicoUrlBodyText("http://test.ne.jp"),new NicoPlainBodyText(@""">こちらをクリック</a>") })});
        }

        [TestCase]
        public void ParseTestCaseUrl2()
        {
            ParseTest(@"本家→http://www.youtube.com/watch?v=13oWAHJuJjM", new INicoCommentBodyText[] { new NicoPlainBodyText("本家→"), new NicoUrlBodyText("http://www.youtube.com/watch?v=13oWAHJuJjM") });
        }

        [TestCase]
        public void ParseTestLiveUrl()
        {
            ParseTest(@"http://live.nicovideo.jp/watch/lv146793663", new INicoCommentBodyText[] { new NicoUrlBodyText("http://live.nicovideo.jp/watch/lv146793663") });
        }
        
        [TestCase]
        public void ParseTestCaseNameRegist()
        {
            ParseTest(@"<testtag> <a href=""http://test.ne.jp"">こちらをクリック</a> @テスト名", 
                new INicoCommentBodyText[] {new NicoHtmlTagBodyText(new INicoCommentBodyText[]{new NicoPlainBodyText("<testtag>")}),
                new NicoPlainBodyText(" "),new NicoAnchorHtmlTagBodyText("こちらをクリック","http://test.ne.jp",
                new INicoCommentBodyText[] {new NicoPlainBodyText(@"<a href="""),new NicoUrlBodyText("http://test.ne.jp"),new NicoPlainBodyText(@""">こちらをクリック</a>")}),new NicoPlainBodyText(" "),new NicoNameRegistRequestBodyText("@テスト名","テスト名")});
        }

        [TestCase]
        public void ParseTestCaseError()
        {
            ParseTest(@"/play smile:sm10370862 main ""【最高音質】雨／川田まみ【とある魔術の禁書目録】""",
                new INicoCommentBodyText[] { new NicoCommentCommandBodyText(@"/play "),new NicoPlainBodyText(@"smile:"), new NicoVideoIdBodyText(@"sm10370862"), new NicoPlainBodyText(@" main ""【最高音質】雨／川田まみ【とある魔術の禁書目録】""") });
        }

        [TestCase]
        public void ParseTestKana()
        {
            var bodyTexts = NicoCommentBody.Parse("あ・・・");


        }
        public void ParseTest(string body,ICollection<INicoCommentBodyText> texts)
        {
            var bodyTexts = NicoCommentBody.Parse(body);

            Assert.AreEqual(bodyTexts.Texts.Count, texts.Count);

            for (int index = 0;index < bodyTexts.Texts.Count;index++)
            {
                Assert.AreEqual(bodyTexts.Texts.ElementAt(index).BodyType, texts.ElementAt(index).BodyType);
                if (bodyTexts.Texts.ElementAt(index).HasCurrentBodyText) Assert.AreEqual(bodyTexts.Texts.ElementAt(index).Text, texts.ElementAt(index).Text);
                
            }
        }
    }
}
